'use strict';
define(function(require, exports, module) {

	var app = angular.module('myApp', ['ui.router']);
	app.config(['$controllerProvider', '$compileProvider', '$filterProvider', '$provide', '$stateProvider', '$urlRouterProvider', function($controllerProvider, $compileProvider, $filterProvider, $provide, $stateProvider, $urlRouterProvider) {

		app.register = {
			controller: $controllerProvider.register,
			directive: $compileProvider.directive,
			filter: $filterProvider.register,
			factory: $provide.factory,
			service: $provide.service,
			stateProvider: $stateProvider,
			urlRouterProvider: $urlRouterProvider
		};

		//注册路由controller.js文件的加载方法
		app.getRouteResolve = function(src){
			return {
				load : function($$q, $rootScope) {
					var deferred = $$q.defer();
					var dependencies = src;

					require.async(dependencies, function(mod) {

						console.info("lazy load route controller.");

						mod.init(app);

						$rootScope.$apply(function() {
							deferred.resolve();
						});
					});
					return deferred.promise;
				}
			};
		};

		// app.loadMod = function(src){
		// 	var app = this;
		// 	var mod = require(src);
		// 	mod.init(app);
		// };

		//加载common组件
		// require("../common/mod.js").init(app);
		//加载指令
		require("../common/directive/app-header/app-header").init(app);
    	require("../common/directive/app-footer/app-footer").init(app);
    	// require("../common/directive/app-nav/app-nav").init(app);
	}]);

    // //加载指令
    // app.loadMod("../common/directive/mod.js");
    //运行出错。此时app.config中的方法还未执行，所以loadMod属性方法还未注册

	//启动应用
	angular.bootstrap(document.body, ['myApp']);

	console.info("app starting...");
});